class BlackDeathInventoryManager extends InventoryManager
	config(Game);


simulated function bool AddInventory(Inventory NewItem, optional bool bDoNotActivate)
{
	local Inventory Item, LastItem;
	// The item should not have been destroyed if we get here.
	if( (NewItem != None) && !NewItem.bDeleteMe )
	{
		// if we don't have an inventory list, start here
		if( InventoryChain == None )
		{
			InventoryChain = newItem;
		}
		else
		{
			// Skip if already in the inventory
			for (Item = InventoryChain; Item != None; Item = Item.Inventory)
			{
				if( Item == NewItem )
				{
					return FALSE;
				}
				LastItem = Item;
			}
			LastItem.Inventory = NewItem;
		}

		//`LogInv("adding" @ NewItem @ "bDoNotActivate:" @ bDoNotActivate);
		
		NewItem.SetOwner( Instigator );
		NewItem.Instigator = Instigator;
		NewItem.InvManager = Self;
		//`log("adding inventory"@NewItem);
		//NewItem.GivenTo( Instigator);

		// Trigger inventory event
		Instigator.TriggerEventClass(class'SeqEvent_GetInventory', NewItem);
		return TRUE;
	}

	return FALSE;
}

simulated function RemoveFromInventory(Inventory ItemToRemove)
{
	local Inventory Item;
	local bool		bFound;

	if( ItemToRemove != None )
	{
		if( InventoryChain == ItemToRemove )
		{
			bFound = TRUE;
			InventoryChain = ItemToRemove.Inventory;
		}
		else
		{
			// If this item is in our inventory chain, unlink it.
			for(Item = InventoryChain; Item != None; Item = Item.Inventory)
			{
				if( Item.Inventory == ItemToRemove )
				{
					bFound = TRUE;
					Item.Inventory = ItemToRemove.Inventory;
					break;
				}
			}
		}

		if( bFound )
		{
			`LogInv("removed" @ ItemToRemove);
			ItemToRemove.ItemRemovedFromInvManager();
			ItemToRemove.SetOwner(None);
			ItemToRemove.Inventory = None;
		}

		// make sure we don't have other references to the item
		if( ItemToRemove == Instigator.Weapon )
		{
			Instigator.Weapon = None;
		}

		if( Instigator.Health > 0 && Instigator.Weapon == None && Instigator.Controller != None )
		{
			`LogInv("Calling ClientSwitchToBestWeapon");
			Instigator.Controller.ClientSwitchToBestWeapon(TRUE);
		}
	}
}

simulated function SetItemsHidden(bool bIsVisible)
{
	local Inventory Inv;
	//`log("setting tiems hidden");
	if(InventoryChain != none)
	{
		Inv = InventoryChain;
		while(Inv != none)
		{
			//`log("Hideing item"@Inv);
			if(BlackDeathWeapon(Inv) != none)
				BlackDeathWeapon(Inv).ChangeVisibility(bIsVisible);
			Inv = Inv.Inventory;
		}
	}
}

simulated function bool IsAnyPendingFire()
{
	local int i, pendLength;
	pendLength = GetPendingFireLength(Instigator.Weapon);
	for(i = 0; i < pendLength; i++)
	{
		if(IsPendingFire(Instigator.Weapon, i))
		{
			return true;
		}
	}
	return false;
}

defaultproperties
{
	PendingFire(0)=0
	PendingFire(1)=0
}